package cn.broadsense.common.core.page;

import cn.broadsense.common.constant.HttpStatus;
import cn.broadsense.common.core.domain.R;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

import static cn.broadsense.common.constant.HttpStatus.SUCCESS;

/**
 * 表格分页数据对象
 *
 * @author ruoyi
 */
@ApiModel("表格分页数据")
public class TableDataInfoResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    public static final int SUCCESS = HttpStatus.SUCCESS;

    /**
     * 总记录数
     */

    @ApiModelProperty("总记录数")
    private long total;

    /**
     * 列表数据
     */
    @ApiModelProperty("列表数据")
    private T rows;

    @ApiModelProperty("扩展字段")
    private Object extended1;


    /**
     * 消息状态码
     */
    @ApiModelProperty("消息状态码")
    private int code;

    /**
     * 消息内容
     */
    @ApiModelProperty("消息内容")
    private String msg;

    /**
     * 表格数据对象
     */
    public TableDataInfoResult() {
    }

    /**
     * 分页
     *
     * @param list  列表数据
     * @param total 总记录数
     */
    public TableDataInfoResult(T list, int total) {
        this.rows = list;
        this.total = total;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public T getRows() {
        return rows;
    }

    public void setRows(T rows) {
        this.rows = rows;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getExtended1() {
        return extended1;
    }

    public void setExtended1(Object extended1) {
        this.extended1 = extended1;
    }


    public static <T> TableDataInfoResult<T> ok(T data, long total) {
        TableDataInfoResult<T> apiResult = new TableDataInfoResult<>();
        apiResult.setCode(SUCCESS);
        apiResult.setRows(data);
        apiResult.setMsg("获取成功");
        apiResult.setTotal(total);
        return apiResult;
    }
}
